﻿using Rabbit.Domain.Entity;
using Rabbit.Domain.IRepository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Rabbit.Domain.Repository
{
    public class MachinRepository: IMachinRepository
    {
        private readonly RbacContext _context;

        public MachinRepository(RbacContext context)
        {
            _context = context;
        }

        public int GeMachinAdd(Machining Machin)
        {
            var list=_context.Machinings.Add(Machin);
            return _context.SaveChanges();
        }


        public dynamic GetMachinFind(int id)
        {
            var list=_context.Machinings.FirstOrDefault(x=>x.MachiningId == id);
            return list;
        }

        public List<Machining> GetMachinShow(int id)
        {
            var list=_context.Machinings.Where(x=>x.GoodInfoId == id).ToList();
            return list;
        }

        public int GetMachinUpd(Machining Machin)
        {
            var list=_context.Machinings.FirstOrDefault(x=>x.MachiningId==Machin.MachiningId);
            list.MachiningId= Machin.MachiningId;
            list.GoodInfoId= Machin.GoodInfoId;
            list.MachinFuZe= Machin.MachinFuZe;
            list.MachinClass= Machin.MachinClass;
            _context.Machinings.Update(list);
            return _context.SaveChanges();
        }


        /// <summary>
        /// 供应商信息显示
        /// </summary>
        /// <returns></returns>
        public List<Gongyingshang> GetGongyingshangShow()
        {
            var list=_context.Gongyingshangs.ToList();
            return list;
        }

        public List<Machiningenterprise> GetMachiningenterpriseShow()
        {
           var list=_context.Machiningenterprises.ToList();
            return list;
        }

        public int GetGongyingshangXiu(Machiningenterprise Machin)
        {
            var list=_context.Machiningenterprises.FirstOrDefault(x=>x.MachiningEnterpriseId==Machin.MachiningEnterpriseId);
            list.MachiningEnterpriseId= Machin.MachiningEnterpriseId;
            list.MachiningEnterpriseNumber= Machin.MachiningEnterpriseNumber;
            list.MachiningEnterpriseName= Machin.MachiningEnterpriseName;
            _context.Machiningenterprises.Update(list);
            return _context.SaveChanges();
        }
    }
}
